<?php

/**
 * TODO: Make a base-controller class instead. This could inherit from that. 
 */

class MasterController {

    protected $view ;
    protected $model ;

    /**
     * bind a view and a model if exists to the controller
     * @param object $view
     * @param object $model
     *
     * TODO: Base-classes of view and model so we can type this.
     */
    public function __construct($view = null, $model = null ) {
        if($view !== null) {
            $this->view = $view ;
        }
        if($model !== null) {
            $this->model = $model ;
        }
    }

    /**
     * This is the main routing for the MVC. 
     *
     * @return string $ret
     *
     * TODO: Lift it out to it's own file? Routing.php
     */   
    public function doControll() {

        // TODO find a way to do this automatically based on file-name and file-structure
        // Handle the views
        $lm = new LoginModel() ;
        $fm = new FileModel() ;
        
        // Handle the views
        $lv = new LoginView($lm) ;
        $fv = new FileView($fm) ;

        // And handle the Controllers
        $lc = new LoginController($lv, $lm) ;
        $fc = new FileController($fv, $fm, $lm) ;
        
        $ret = "" ;

        // Add the styles we are going to use
        $this->view->addStyleSheet("styles.css") ;

        // Build the basic webb-structure
        $body = "" ;
        
        $body .= $lc->doControll() ;
        $body .= $fc->doControll() ;
        $body .= $this->view->addDiv("", array('class' => 'clr')) ;
        $body = $this->view->addDiv($body, array('id' => 'container')) ;

        $ret .= $this->view->getXHtml(array('body'=>$body)) ;

        return $ret ;

    }

}

